﻿'========================================================================
'功能:駐廠人員及IT必要簽核人維護
'作者:andy
'日期: 2011/7/20
'========================================================================
Partial Class WebForm_OnSiteMaintain
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            If Not ChkProgramRight(1) Then '查詢
                btnInsert.Visible = False
                gvOnSite.Visible = False
            End If
            If Not ChkProgramRight(2) Then '新增
                btnInsert.Visible = False
            End If


            If Not ChkProgramRight(3) Then '編輯
                gvOnSite.Columns(0).Visible = False
            End If

            If Not ChkProgramRight(4) Then 'Delete
                gvOnSite.Columns(1).Visible = False
            End If

        End If

    End Sub



    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        hiKind.Value = "1"
        gvOnSite.EditIndex = 0
        gvOnSite.PageIndex = 0
        gvOnSite.DataBind()

    End Sub

    Protected Sub gvOnSite_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvOnSite.RowCancelingEdit
        gvOnSite.EditIndex = -1
        hiKind.Value = ""
    End Sub

    Protected Sub gvOnSite_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvOnSite.RowUpdated
        gvOnSite.EditIndex = -1
        hiKind.Value = ""
    End Sub

  
   
   
   
   
    Protected Sub gvOnSite_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvOnSite.RowDeleting
        Dim Site As String = CType(gvOnSite.Rows(e.RowIndex).FindControl("btnDelete"), Button).CommandArgument.ToString
        dsOnSite.DeleteParameters("Site").DefaultValue = Site
        dsOnSite.Delete()
        e.Cancel = True
        gvOnSite.DataBind()
    End Sub

    Protected Sub gvOnSite_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvOnSite.RowUpdating
        Dim ddlSite As DropDownList = gvOnSite.Rows(e.RowIndex).FindControl("ddlSite")
        Dim dao As Telecom.DAO.OnSiteDAO = New Telecom.DAO.OnSiteDAO(hiDBName.Value)
        If (ddlSite.Enabled) Then ''新增時
            '檢查是否已有該資料
            If ddlSite.SelectedValue = "" Then
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrSiteEmpty"))
                e.Cancel = True
                Exit Sub
            End If

            If dao.GetOnSite("", ddlSite.SelectedValue).Rows.Count > 0 Then
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrSiteExist"))
                e.Cancel = True
                Exit Sub
            End If
        End If



        Dim udao As OAMS.DAO.UsersDAO = New OAMS.DAO.UsersDAO(hiDBName.Value)

        ''檢查填入的人是否OK
        Dim txtIT_Approver As TextBox = gvOnSite.Rows(e.RowIndex).FindControl("txtIT_Approver")
        Dim txtOnSiteUID As TextBox = gvOnSite.Rows(e.RowIndex).FindControl("txtOnSiteUID")
        If txtIT_Approver.Text <> "" Then

            If udao.UserIsExist(txtIT_Approver.Text) = False Then
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrApprove"))
                e.Cancel = True
                Exit Sub
            End If

        End If

        If txtOnSiteUID.Text <> "" Then

            If udao.UserIsExist(txtOnSiteUID.Text) = False Then
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("ErrOnSite"))
                e.Cancel = True
                Exit Sub
            End If

        End If

    End Sub

    Protected Sub btnIT_Approver_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim txtIT_Arrpover As TextBox = CType(gvOnSite.Rows(gvOnSite.EditIndex).FindControl("txtIT_Approver"), TextBox)
        PopupFormForAjax(gvOnSite, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "AUOREF.dbo.emp_data_all", dbName, "1", txtIT_Arrpover.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
    End Sub

    Protected Sub btnOnSiteUID_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim txtOnSiteUID As TextBox = CType(gvOnSite.Rows(gvOnSite.EditIndex).FindControl("txtOnSiteUID"), TextBox)
        PopupFormForAjax(gvOnSite, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "AUOREF.dbo.emp_data_all", dbName, "1", txtOnSiteUID.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
    End Sub

    
End Class
